import request from '@/utils/request'

export function fetchList(areaCode) {
  return request({
    url: '/base/dictarea/list',
    method: 'get',
    params: { areaCode }
  })
}

export function createDictArea(dictarea) {
  return request({
    url: '/base/dictarea/create',
    method: 'post',
    data: dictarea
  })
}

export function updateDictArea(dictarea) {
  return request({
    url: '/base/dictarea/update',
    method: 'post',
    data: dictarea
  })
}

export function deleteDictArea(areaCode) {
  return request({
    url: '/base/dictarea/delete',
    method: 'post',
    data: { areaCode }
  })
}

export function updateAllDictAreas(year) {
  return request({
    url: '/base/dictarea/updateAll',
    method: 'post',
    params: { year }
  })
}

export function importDictArea(fileobj, obj) {
  if (!fileobj || !fileobj.file) {
    return {}
  }
  const param = new FormData()
  if (obj) {
    for (const key of obj) {
      param.append(key, obj[key])
    }
  }
  param.append('file', fileobj.file)
  return request({
    method: 'post',
    url: '/base/dictarea/import',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

export function exportDictArea(filterText) {
  return request({
    url: '/base/dictarea/export',
    method: 'get',
    params: { filterText }
  })
}

export function exportDictAreaTemplate() {
  return request({
    url: '/base/dictarea/template/export',
    method: 'get'
  })
}
